#!/usr/bin/env node

const mysql = require('mysql2/promise'),
      log   = console.log,
      Koa   = require('koa'),
      app   = new Koa(),
      Router = require('koa-router'),
      router = new Router(),
      fs    = require('fs'),
      path  = require('path'),
      cors  = require('koa2-cors'),
      http  = require('http'),
      https = require('https');

let con = mysql.createPool({
    host:'154.8.156.240',
    port:'2020',
    user:'root',
    password:'Ljj0222.',
    database:'tuijian'
});
//查询
async function getlogin(user_name,password){
  const sql = `select * from manager_table where user_name = '${user_name}' and password = '${password}'`;
  let [rows] = await con.execute(sql);
  return rows;
}
//全部
async function getlogin1(){
  const sql = `select * from manager_table`;
  let [rows] = await con.execute(sql);
  return rows;
}
//添加
async function insertl(user_name,password){
  const sql = `insert into manager_table(user_name,password) values('${user_name}','${password}');`
  let [rows] = await con.execute(sql);
  return rows;
}
//修改
async function upl(id,user_name,password){
  const sql = `update manager_table set user_name ='${user_name}',password = '${password}' where id = '${id}'`;
  let [rows] = await con.execute(sql);
  return rows;
}
//删除
async function dell(id){
  const sql = `delete from manager_table where id = '${id}'`;
  let [rows] = await con.execute(sql);
  return rows;
}
(async function(){
    //log(await getAreas());
})();

module.exports.getlogin = getlogin;
module.exports.getlogin1 = getlogin1;
module.exports.insertl = insertl;
module.exports.upl = upl;
module.exports.dell =dell;
